/**
 * 文件名称：UserAction.java
 * 文件版权：ChinaParasol Technologies Co., Ltd. Copyright 2000-2020,  All rights reserved
 * 文件描述：<描述>
 * 创建作者：Administrator
 * 创建时间：Jan 5, 2013
 * 修改内容：<修改内容>
 */
package com.parasol.hcerp.service.user.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.parasol.hcerp.common.action.ParasolAction;
import com.parasol.hcerp.service.user.domain.UserBean;
import com.parasol.hcerp.service.user.service.UserService;

/**
 * 用户管理
 * @author  Administrator
 * @version V1.0, Jan 5, 2013
 */
public class UserAction extends ParasolAction
{

    /** 注释内容 */
    private static final long serialVersionUID = 974966411329855015L;
    
    private UserBean userBean = null;
    
    private UserService userService = null;
    
    private String userid = null;
    
    public String getUserid()
    {
        return userid;
    }

    public void setUserid(String userid)
    {
        this.userid = userid;
    }

    public UserBean getUserBean()
    {
        return userBean;
    }

    public void setUserBean(UserBean userBean)
    {
        this.userBean = userBean;
    }

    public UserService getUserService()
    {
        return userService;
    }

    public void setUserService(UserService userService)
    {
        this.userService = userService;
    }

    public String login()
    {
        super.clientCache();
        int result = userService.login(userBean);
        if (result == 0)
        {
            return ERROR;
        }
        
        userBean = userService.queryForSession(userBean);
        HttpSession session = super.getSession();
        session.setAttribute("userSession", userBean);
        return SUCCESS;
    }
    
    public String queryForList()
    {
        super.clientCache();
        List<UserBean> userList = userService.queryForList();
        HttpServletRequest request = super.getRequest();
        request.setAttribute("userList", userList);
        return SUCCESS;
    }
    
    public String saveForJump()
    {
        super.clientCache();
        return SUCCESS;
    }
    
    public String saveForUser()
    {
        super.clientCache();
        int result = userService.checkExist(userBean);
        if (result == 1)
        {
            HttpServletRequest request = super.getRequest();
            request.setAttribute("errormessage", "账号已经存在");
            return ERROR;
        }
        
        userService.saveForUser(userBean);
        
        List<UserBean> userList = userService.queryForList();
        HttpServletRequest request = super.getRequest();
        request.setAttribute("userList", userList);
        return SUCCESS;
    }
    
    public String updateForJump()
    {
        super.clientCache();
        userBean = userService.queryForUser(userid);
        HttpServletRequest request = super.getRequest();
        request.setAttribute("userBean", userBean);
        return SUCCESS;
    }
    
    
    public String updateForUser()
    {
        super.clientCache();
        int result = userService.checkExist(userBean);
        if (result == 1)
        {
            HttpServletRequest request = super.getRequest();
            request.setAttribute("errormessage", "账号已经存在");
            return ERROR;
        }
        
        userService.updateForUser(userBean);
        List<UserBean> userList = userService.queryForList();
        HttpServletRequest request = super.getRequest();
        request.setAttribute("userList", userList);
        return SUCCESS;
    }
    
    
    public String deleteForUser()
    {
        super.clientCache();
        userService.deleteForUser(userid);
        
        List<UserBean> userList = userService.queryForList();
        HttpServletRequest request = super.getRequest();
        request.setAttribute("userList", userList);
        return SUCCESS;
    }
    
    public String showForUser()
    {
        super.clientCache();
        userBean = userService.queryForUser(userid);
        HttpServletRequest request = super.getRequest();
        request.setAttribute("userBean", userBean);
        return SUCCESS;
    }
    
}
